package com.hs.server.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hs.server.config.MyConfig;
import com.hs.server.domain.ShResourcexx;
import com.hs.server.domain.VehQueuexxb;
import com.hs.server.domain.VehZnshinfo;
import com.hs.server.dto.OcrTestDto;
import com.hs.server.runnable.WorkCustomer;
import com.hs.server.service.ShResourcexxService;
import com.hs.server.service.impl.JianyanHsServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/ocr")
@Slf4j
public class OcrController {
    @Autowired
    private ShResourcexxService shResourcexxService;
    @Autowired
    private MyConfig myConfig;
    @PostMapping("/test")
    public Object test(@RequestBody OcrTestDto dto){
        ShResourcexx shResourcexx = shResourcexxService.getOne(new QueryWrapper<ShResourcexx>().eq("zt","1").last("LIMIT 1"));
        VehQueuexxb vehQueuexxb = new VehQueuexxb();
        vehQueuexxb.setZpzl(dto.getZpzl());
        vehQueuexxb.setJyx(dto.getJyx());
        vehQueuexxb.setZt("0");
        JianyanHsServiceImpl jianyanService = new JianyanHsServiceImpl(shResourcexx.getIpdz(),Integer.valueOf(shResourcexx.getDkh()));
        WorkCustomer workCustomer = new WorkCustomer(vehQueuexxb, new ShResourcexx(),jianyanService);
        VehZnshinfo vehZnshinfo = new VehZnshinfo();
        BeanUtils.copyProperties(dto,vehZnshinfo);
        vehZnshinfo.nullStringsToEmpty();
        String result = workCustomer.parseGrpc(shResourcexx,vehQueuexxb,vehZnshinfo, dto.getUrl());
        log.info("{}==>识别返回：{}",dto.getUrl(),result);
        return result;
    }

    @GetMapping("/getStartTime")
    public String getStartTime(){
        return myConfig.startTime;
    }
}
